import React , { Component } from 'react';
import { withRouter,NavLink,Switch,Redirect,Route} from 'react-router-dom';

import {connect} from 'react-redux';

import {AddTodo,RemoveTodo} from './redux/Action.js';

class View extends Component {
    render(){
        const {id,text,onRemoveFn} = this.props;
        return (
            <li key={id}>
                <span>{id}{text}</span>
                <em onClick={onRemoveFn}>删除</em>
            </li>
        )
    }
}
function mapStateToProps(state) {
  return {
      isList:state.add
  }
}
//是一个函数，会得到dispatch和ownProps（容器组件的props对象）两个参数。
const mapDispatchToProps = (dispatch, ownProps) => {
	const {id} = ownProps;
	return {
		onRemoveFn: () => dispatch(RemoveTodo(id))
	}
};

export default connect(mapStateToProps,mapDispatchToProps)(View);
